const Puppeteer = require("puppeteer-core");


const main = async () => {
    //启动浏览器
    const browser = await Puppeteer.launch({
        //设置谷歌浏览器可执行文件 （exe）的位置
        executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
        //无头模式（后台运行），是否可见浏览器窗口，trus = 不可见，false = 可见
        headless: false,
        //设置浏览器可视区域大小
        defaultViewport: {
            width: 1366,
            height: 768

        }
    });

    const page = await browser.newPage();
    await page.goto('http://car.autohome.com.cn/');
    const brands = await page.$$eval('#cartree li', (doms) => {
        //这里面是在浏览器运行
        // console.log('doms count:',doms.length);
        // console.log('content',doms[5].innerText);
        const _brands = [];
        for (let item of doms) {
            let brand = item.innerText.split('(')[0];
            _brands.push({
                brand: brand
            });
        }
        return _brands;
    });
    console.log(brands);
};
main();